"use strict";
cc._RF.push(module, 'cf2e8DHc2dNf7FZRRuG8SPT', 'startGame');
// script/index/startGame.js

"use strict";

cc.Class({
  "extends": cc.Component,
  properties: {
    StartBtnNode: {
      "default": null,
      type: cc.Node
    },
    titleNode: {
      "default": null,
      type: cc.Node
    },
    loadPrefab: {
      "default": null,
      type: cc.Prefab
    }
  },
  show: function show(ne) {
    this.node = ne;
    this.node.active = true;
  },
  hide: function hide(ne) {
    this.node = ne;
    this.node.active = false;
  },
  onLoad: function onLoad() {
    this.anim = 'startBtn';
    this.startAnim = this.StartBtnNode.getComponent(cc.Animation);
    this.titleAnim = this.titleNode.getComponent(cc.Animation);
    this.bgNode = this.node.getChildByName('bg');
    this.times = this.startAnim.play('startBtn').duration;
    this.show(this.node);
    this.show(this.StartBtnNode); // this.setAnim(this.startAnim,'btnScale');

    this.startAnim.ShowbtnScaleFun = function () {
      this.setAnim(this.startAnim, 'btnScale');
    }.bind(this);
  },
  start: function start() {
    var titleTimes = this.times * 2000;
    this.show(this.titleNode);
    setTimeout(function () {
      this.playTitle();
    }.bind(this), titleTimes);
  },
  playTitle: function playTitle() {
    this.setAnim(this.titleAnim, 'action01');

    this.titleAnim.startItemAni = function () {
      this.setAnim(this.titleAnim, 'action02');
    }.bind(this);

    this.titleAnim.ShowAcitionTr = function () {
      this.setAnim(this.titleAnim, 'action03');
    }.bind(this);
  },
  setAnim: function setAnim(ne, anim) {
    //  var duration = 0;
    if (this.anim == anim) {
      return;
    }

    this.anim = anim;
    this.nodeAnim = ne;
    this.animState = this.nodeAnim.play(anim); // duration = this.animState.duration;
    // return duration;
  },
  onClickPlayGame: function onClickPlayGame(target, data) {
    if (data == '开始游戏') {
      this.hide(this.StartBtnNode);
      this.hide(this.titleNode); // createLoad(this.node);

      this.getLoadBar();
      cc.director.preloadScene('game', function () {
        cc.director.loadScene("game"); //console.log(this.getLoadBar());
      }); //console.log(this.getLoadBar());
    } else {
      console.log('加载失败');
    } // cc.director.loadScene("game");

  },
  getLoadBar: function getLoadBar() {
    var load = cc.instantiate(this.loadPrefab);
    this.bgNode.addChild(load);
    load.x = 0;
    load.y = -240;
    this.loadScr = load.getComponent('load');
    this.loadScr.setProgress(1); // console.log(loading);
  },
  update: function update(dt) {}
});

cc._RF.pop();